Skip to content

Optimize RawBsonDocument encode and decode #1913

Draft
vbabanin wants to merge 4 commits into
mongodb:mainfrom
vbabanin:JAVA-6133
Draft

Optimize RawBsonDocument encode and decode #1913
vbabanin wants to merge 4 commits into
mongodb:mainfrom
vbabanin:JAVA-6133

Conversation

@vbabanin
Copy link
Copy Markdown
Member

@vbabanin vbabanin commented Mar 17, 2026

  • Add BsonWriter.pipe(byte[], int, int) with BsonBinaryWriter override to write raw BSON bytes directly to the output, avoiding intermediate object allocation on the encode path
  • Add BsonInput.pipe(BsonOutput, int) to remove the temporary byte[] copy in BsonBinaryWriter.pipeDocument() on both encode and decode paths
  • Add public getByteBacking(), getByteOffset(), getByteLength() on RawBsonDocument to expose the backing byte array

//TODO unit/integration/perf tests

JAVA-6133

…e allocations

- Add BsonWriter.pipe(byte[], int, int) with BsonBinaryWriter override to write raw BSON bytes directly to the output, avoiding intermediate object allocation on the encode path
- Add BsonInput.pipe(BsonOutput, int) to remove the temporary byte[] copy in BsonBinaryWriter.pipeDocument() on both encode and decode paths
- Add public getByteBacking(), getByteOffset(), getByteLength() on RawBsonDocument to expose the backing byte array

JAVA-6133
@vbabanin vbabanin self-assigned this Mar 17, 2026
@vbabanin vbabanin changed the title Optimize RawBsonDocument encode and decode by eliminating intermediat… Optimize RawBsonDocument encode and decode Mar 17, 2026
vbabanin added 3 commits May 19, 2026 09:19
- Removes pipe(byte[], int, int) from BsonWriter interface to avoid coupling it to concrete IO classes; dispatches via instanceof BsonBinaryWriter in the codec instead
- Renames getByteBacking() to getBackingArray() for clarity
- Validates minimum BSON document size before writing raw bytes, consistent with the reader-based pipe path
- Adds tests for the raw-byte pipe happy path and invalid-size rejection

JAVA-6133
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant